#!/bin/bash
echo "检查是否安装docker,docker-compose环境"
docker -v
if [ $? -eq  0 ]; then
 echo "检查到Docker已安装!"
else
 echo "安装docker环境..."
 curl https://gitee.com/ligson/centos7script/raw/master/crux-tools/cruxInstall.sh | bash -s init
fi
if [ -d "/data/docker/service/node-exporter/" ];then
  echo "/data/docker/service/redis 文件夹已经存在,请手动确认后删除该目录,再执行创建"
  exit
fi
if [ ! -d "/data/docker/service/" ];then
  mkdir -p /data/docker/service
fi
cd /data/docker/service
echo "开始下载node-exporter包" 
wget https://zwfile.yonyougov.tech/share/crux-tools/promethus/node-exporter.tar.gz --no-check-certificate 
echo "解压node-exporter" 
tar -zxvf node-exporter.tar.gz
rm -rf node-exporter.tar.gz 
cd /data/docker/services/node-exporter
echo "下载镜像文件"
wget https://zwfile.yonyougov.tech/share/crux-tools/exporter/node-exporter.tar.gz --no-check-certificate
docker load -i node-exporter.tar.gz
rm -rf node-exporter.tar.gz
sh replaceIp.sh
echo "启动服务"
docker network ls | grep mynetwork
if [ $? -eq  0 ]; then
 echo "Docker网络mynetwork已存在!"
else
 echo "创建docker网络"
 docker network create mynetwork
fi
if [ ! -z "$1" ];then
  echo "修改register.sh中consulUrl=值"
  sed -ie "6s/\/consul/\/$1/g" register.sh
fi
docker-compose up -d
sh register.sh
